<template>
  <PageLayout>
    <template #header>
      <BasicForm
        :options="queryOptions"
        @ok="onQueryDataByParams"
        :labelWidth="90"
      ></BasicForm>
    </template>
    <div class="table-box">
      <div class="head-box">
        <div class="title">财务管理</div>
        <a-space :size="16">
          <a-button type="primary" @click="importFile">数据导出</a-button>
        </a-space>
      </div>
      <div class="bg-fff">
        <!-- :apiFetch="apiFetch"  -->
        <BasicTable
          ref="tableRef"
          :columns="columns"
          :query-params="queryData"
          :apiFetch="postAgentWithdrawPage"
        >
          <template #bodyCell="{ column, record }">
            <!-- <template v-if="column.key === 'action'">
              <a-space class="space-btn--box" :size="10">
                <a class="btn" @click="showDetail(record)">查看详情</a>
              </a-space>
            </template> -->
          </template>
        </BasicTable>
      </div>
    </div>

    <DetailModal ref="detailModalRef" :data="dataDetail"></DetailModal>
  </PageLayout>
</template>

<script setup>
import DetailModal from "./components/detail-modal.vue";
import { postAgentWithdrawPage, postFinancialBillExport } from "@/api/common";
import { useStoreCommonEnum } from "@/store";
import { message } from "ant-design-vue";
const storeCommonEnum = useStoreCommonEnum();
const router = useRouter();
const queryOptions = ref([
  {
    name: "代理商名称",
    type: "input",
    value: "",
    placeholder: "请输入",
    filed: "agentName",
  },
  {
    name: "手机号码",
    type: "input",
    value: "",
    placeholder: "请输入",
    filed: "shopName",
  },
  {
    name: "提现状态",
    type: "select",
    value: [],
    placeholder: "请选择",
    filed: "status",
    list: [
      {
        label: "提现中",
        value: "0",
      },
      {
        label: "提现成功",
        value: "1",
      },
      {
        label: "提现失败",
        value: "2",
      },
    ],
    attrs: { mode: "multiple" },
  },
  {
    name: "提现时间",
    type: "range-picker",
    value: [],
    placeholder: "请选择",
    filed: "rangeDate",
    dateFields: ["startWithdrawTime", "endWithdrawTime"],
  },
]);
const columns = [
  {
    title: "序号",
    dataIndex: "index",
    width: "80px",
    customRender: (record) => `${record.index + 1}`,
  },
  {
    title: "代理商姓名",
    dataIndex: "agentName",
    key: "agentName",
    width: "200px",
    ellipsis: true,
  },
  {
    title: "手机号码",
    dataIndex: "phone",
    key: "phone",
    width: "150px",
    ellipsis: true,
  },
  {
    title: "提现金额",
    dataIndex: "amountYuan",
    key: "amountYuan",
    width: "150px",
    ellipsis: true,
  },
  {
    title: "提现时间",
    dataIndex: "withdrawTime",
    key: "withdrawTime",
    width: "150px",
    ellipsis: true,
  },
  {
    title: "提现状态",
    dataIndex: "status",
    key: "status",
    width: "150px",
    ellipsis: true,
    customRender: ({ record }) =>
      record.status == 0
        ? "提现中"
        : record.status == 1
        ? " 提现成功"
        : "提现失败",
  },
];

const queryData = reactive({});
const tableRef = ref(null);
const onQueryDataByParams = (params) => {
  for (let key in params) {
    queryData[key] = params[key];
  }
  tableRef.value.refreshTableData();
};
const detailModalRef = ref(null);
const dataDetail = ref({});
const showDetail = (record) => {
  dataDetail.value = record;
  setTimeout(() => {
    detailModalRef.value.visible = true;
  }, 0);
};
const importFile = () => {
  if (!tableRef.value.data?.length) {
    message.error("暂无数据");
    return;
  }
  const params = {};

  for (let key in queryData) {
    params[key] = queryData[key];
  }
  postFinancialBillExport(params).then((res) => {
    message.success("导出成功");
  });
};

const dataSource = ref(
  Array.from({ length: 11 }, () => ({
    spaceName: "2121",
  }))
);
</script>

<style lang="less" scoped></style>
